package org.example.controller;

import org.example.Mapper.Studentmapper;
import org.example.Service.StudentsService;
import org.example.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController //controller+ResponseBody给前端返回一个jons对象
@RequestMapping("/students")
public class StudentsController {

    @Autowired
    private StudentsService studentsService;

    //get请求 查询
    @GetMapping("/getid")
    public Student getid(Integer id) {
        Student getid = studentsService.getid(id);
        return getid;
    }
    @GetMapping("/getall")
    public List<Student> getAll() {
        List<Student> getall = studentsService.getall();
        return getall;
    }
    /*@PostMapping("/add")
    public String insert(Student student) {
        studentmapper.insert(student);
        return "success";

    }*/

    @PostMapping("/insert")
    public String insert(Integer id, String name, Integer age, String gender) {
        Student student = new Student(id, name, age, gender);
        studentsService.insert(student);
        return "success";

    }


    @PostMapping("/delete")
    public String delete(Integer id) {
        studentsService.delete(id);
        return "success";
    }
    @PostMapping("/update")
    public String update(Student student) {
        studentsService.update(student);
        return "success";
    }


}
